package com.zdsoft.crm.service.auth.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zdsoft.crm.dao.auth.ISysUserMapper;
import com.zdsoft.crm.entity.auth.SysUser;
import com.zdsoft.crm.service.auth.ISysUserService;
import com.zdsoft.crm.vo.PageVo;


@Service
@Transactional
public class SysUserServiceImpl implements ISysUserService {

	@Autowired
	private ISysUserMapper dao;
	
	
	@Override
	public PageVo findPage(Integer pageNum, Integer pageSize, String username) {
		PageVo pageVo = new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		int beginIndex = (pageNum - 1) * pageSize;
		int endIndex = beginIndex + pageSize;
		pageVo.setList(dao.pageListWhere(beginIndex, endIndex,username));// TODO oracle
															// 动态分页查询有问题:
															// script解析不出来
		// pageVo.setList(dao.pageList((pageNum - 1) * pageSize, pageSize));
		// mysql
		// pageVo.setList(dao.pageList(pageNum, pageSize));
		pageVo.setTotalCount(dao.totalCountWhere(username).intValue());
		return pageVo;
	}

	@Override
	public SysUser findById(String id) {		
		return dao.findById(id);
	}


	@Override
	public void deleteUser(String id) {
		dao.deleteUser(id);
		
	}

	/**
	 * 保存用户
	 */
	@Override
	public void saveUser(SysUser user) {
		dao.save(user);
		
	}

	/**
	 * 编辑用户
	 */
	@Override
	public void update(String id,String username, Integer is_admin) {
		
		dao.update(id, username, is_admin);
		
	}

	@Override
	public SysUser findByUserName(String username) {
		return dao.findByUserName(username);
	}

}
